<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
function loadXMLDoc()
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	{
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
		}
	}
	//xmlhttp.open("GET","https://www.runoob.com/try/ajax/ajax_info.txt",true);
    xmlhttp.open("GET","try/ajax/ajax_info.txt",true);
    
	xmlhttp.send();
}
function loadXMLDoc1()
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	{
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
		}
	}
	//xmlhttp.open("GET","https://www.runoob.com/try/ajax/ajax_info.txt",true);
    xmlhttp.open("GET","try/ajax/demo_get.php?t="+ Math.random(),true);
    
	xmlhttp.send();
}
function loadXMLDoc2()
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	{
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
		}
	}
	//xmlhttp.open("GET","https://www.runoob.com/try/ajax/ajax_info.txt",true);
    xmlhttp.open("GET","try/ajax/demo_get2.php?fname=Henry&lname=Ford",true);
    
	xmlhttp.send();
}
function loadXMLDoc3()
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	{
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
		}
	}
	//xmlhttp.open("GET","https://www.runoob.com/try/ajax/ajax_info.txt",true);
    xmlhttp.open("POST","try/ajax/demo_post.php?fname=Henry&lname=Ford",true);
    
	xmlhttp.send();
}
function loadXMLDoc4()
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	{
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
		}
	}
	//xmlhttp.open("GET","https://www.runoob.com/try/ajax/ajax_info.txt",true);
    xmlhttp.open("POST","try/ajax/demo_post.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send("fname=Henry&lname=Ford");
}
function showHint(str)
{
  var xmlhttp;
  if (str.length==0)
  { 
    document.getElementById("txtHint").innerHTML="";
    return;
  }
  if (window.XMLHttpRequest)
  {
    // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
    xmlhttp=new XMLHttpRequest();
  }
  else
  {
    // IE6, IE5 浏览器执行代码
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function()
  {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
      document.getElementById("txtHint1").innerHTML=xmlhttp.responseText;
    }
  }
  //xmlhttp.open("GET","/try/ajax/gethint.php?q="+str,true);
  xmlhttp.open("GET","/try/ajax/test1.php?q="+str,true);
  xmlhttp.send();
}
function showCustomer(str)
{
  var xmlhttp;    
  if (str=="")
  {
    document.getElementById("txtHint").innerHTML="";
    return;
  }
  if (window.XMLHttpRequest)
  {
    // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
    xmlhttp=new XMLHttpRequest();
  }
  else
  {
    // IE6, IE5 浏览器执行代码
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function()
  {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      document.getElementById("txtHint2").innerHTML=xmlhttp.responseText;
    }
  }
  xmlhttp.open("GET","try/ajax/getsite_mysql.php?q="+str,true);
  xmlhttp.send();
}
function connectdb(){
var xmlhttp;
var dbname=document.getElementById("dbname").value
	if (window.XMLHttpRequest)
	{
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("txtHint3").innerHTML=xmlhttp.responseText;
		}
	}
    xmlhttp.open("POST","sql/newdb.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send("dbname="+dbname);
}
function connectdb1(canshu){
var xmlhttp;
var student_name=document.getElementById("student_name").value
var student_xuehao=document.getElementById("student_xuehao").value
	if (window.XMLHttpRequest)
	{
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("txtHint3").innerHTML=xmlhttp.responseText;
		}
	}
    xmlhttp.open("POST","sql/student.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    if(canshu=="姓名"){
    xmlhttp.send("student_name="+student_name);
    }
    else if(canshu=="学号"){
    xmlhttp.send("student_xuehao="+student_xuehao);
    }
}
</script>
</head>
<body>

<div id="myDiv"><h2>使用 AJAX 修改该文本内容</h2></div>
<button type="button" onclick="loadXMLDoc()">修改内容</button>
<button type="button" onclick="loadXMLDoc1()">get内容</button>
<button type="button" onclick="loadXMLDoc2()">get内容并增加信息</button>
<br>
<button type="button" onclick="loadXMLDoc3()">POST内容</button>
<button type="button" onclick="loadXMLDoc4()">POST内容表单</button>
<br>
<hr>
<form action=""> 
输入姓名: <input type="text" id="txt1" onkeyup="showHint(this.value)" />
</form>
<p>提示信息: <span id="txtHint"></span></p> 
<p>提示信息2: <span id="txtHint1"></span></p> 

<form action=""> 
<select name="customers" onchange="showCustomer(this.value)" style="font-family:Verdana, Arial, Helvetica, sans-serif;">
<option value="APPLE">Apple Computer, Inc.</option>
<option value="BAIDU ">BAIDU, Inc</option>
<option value="Canon">Canon USA, Inc.</option>
<option value="Google">Google, Inc.</option>
<option value="Nokia">Nokia Corporation</option>
<option value="SONY">Sony Corporation of America</option>
</select>
</form>
<br>
<div id="txtHint2">客户信息将显示在这...</div>
<br>
<form action=""> 
数据库名称: <input type="text" id="dbname" value="storage.db" />
</form>
<button type="button" onclick="connectdb()">连接数据库</button>
<br>
<form action=""> 
输入姓名: <input type="text" id="student_name" /><button type="button" onclick="connectdb1('姓名')">按姓名查询</button>
<br>
输入学号: <input type="text" id="student_xuehao" /><button type="button" onclick="connectdb1('学号')">按学号查询</button>
</form>
<div id="txtHint3">数据库连接信息将显示在这...</div>
</body>
</html>